const path = require('path')
function resolve(dir) {
	return path.join(__dirname, dir)
}
const isProduction = process.env.NODE_ENV.startsWith('production')
const cdn = {
	css: [],
	js: [
		'https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js',
		'https://cdn.bootcdn.net/ajax/libs/vue-router/3.2.0/vue-router.min.js',
		'https://cdn.bootcdn.net/ajax/libs/vuex/3.5.1/vuex.min.js',
		'https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js',
		'https://gw.alipayobjects.com/os/lib/antv/g2/4.1.14/dist/g2.min.js'
	],
}

module.exports = {
	chainWebpack: (config) => {
		// 生产环境
		config.when(isProduction, (config) => {
			config.entry('app').clear().add('./src/main-prod.js')
			config.set('externals', {
				vue: 'Vue',
				'vue-router': 'VueRouter',
				vuex: 'Vuex',
				axios: 'axios',
				'@antv/g2':'G2'
			})
			config.plugin('html').tap((args) => {
				args[0].cdn = cdn
				return args
			})
		})
		// 开发环境
		config.when(!isProduction, (config) => {
			config.entry('app').clear().add('./src/main-dev.js')
		})
		config.resolve.alias.set('@', resolve('src'))
	},
	css: {
		loaderOptions: {
			less: {
				javascriptEnabled: true,
			},
		},
	},
}
